#!/bin/bash

###############################
# there are some global properties being defined below.
###############################

[[ -n $DEBUG ]] && set -x
set -euo pipefail
IFS=$'\n\t'
version="202510100041"
prog=$(basename "$0")
proxym_path=$(realpath "$0")
proxym_dir=$(dirname "${proxym_path}")
default_editor=$(git config --global --get core.editor || echo "${EDITOR:-vi}")

rc_path="${HOME}/.bashrc"

##############################
# import subcmd or base module below.
# NOTE: please make sure the order of sub module scripts are correct
##############################

source "${proxym_dir}/proxy-cmd/01_base.sh"
source "${proxym_dir}/proxy-cmd/02_configs.sh"
source "${proxym_dir}/proxy-cmd/03_git.sh"
source "${proxym_dir}/proxy-cmd/04_dockerpp.sh"

##############################
# cli entry
##############################

usage() {
  echo "================================================================================"
  echo "Descp: $prog manages proxy"
  echo "Version: ${version}"
  echo "Editor: ${default_editor}"
  echo "Usage: $prog"
  config_usage
  echo ""
  git_usage
  echo ""
  docker_usage
  echo ""
  echo "================================================================================"
}

main() {
  if [[ $# -lt 1 || "$1" == "-h" || "$1" == "--help" ]]; then
    # show help
    usage
    exit 0
  fi
  case "${1}" in
  "config") execute_subcmd_config "${@:2}" ;;
  "git") execute_subcmd_git "${@:2}" ;;
  "docker") execute_subcmd_docker "${@:2}" ;;
  *) usage ;;
  esac

}

main "$@"
